import React, { Component } from 'react'

export default class Child extends Component {
  constructor(){
    super()
    this.state={
        count:0
    }
  }
  static index=0
  static getDerivedStateFromProps(nextProps,nextState){
    console.log('----------',Child.index);
    if(Child.index==0){
        Child.index++
        return{
            count:nextProps.num
        }
    }else{
        if(nextProps.num!=nextState.count){
            return{
                count:nextProps.num
            }
        }
        console.log(')))');
        return null
    }
  
   
  }
  shouldComponentUpdate(nextProps,nextState){
    console.log('nextProps',nextProps);
    console.log('nextState',nextState);
    return true;
  }
  render() {
    console.log('==render==');
    return (
      <div>
        <div>{this.state.count}</div>
        <button onClick={()=>this.setState({count:this.state.count+1})}>+</button>
      </div>
    )
  }
}
